home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / trial / demon / TURNPIKE.1 / CLASSES.ZIP / sun / tools / ZIP / ZipFileInputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-04-14  |  1.5 KB  |  81 lines

  1. package sun.tools.zip;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5.  
  6. class ZipFileInputStream extends InputStream implements ZipConstants {
  7.    private ZipFile zipFile;
  8.    private ZipEntry zipEntry;
  9.    private long pos;
  10.    private long count;
  11.  
  12.    public ZipFileInputStream(ZipFile var1, ZipEntry var2) throws ZipFormatException, IOException {
  13.       this.zipFile = var1;
  14.       this.zipEntry = var2;
  15.       this.init();
  16.    }
  17.  
  18.    public synchronized int read(byte[] var1, int var2, int var3) throws ZipFormatException, IOException {
  19.       if (this.count == 0L) {
  20.          return -1;
  21.       } else {
  22.          if ((long)var3 > this.count) {
  23.             var3 = (int)this.count;
  24.          }
  25.  
  26.          int var4 = this.zipFile.read(this.pos, var1, var2, var3);
  27.          if (var4 == -1) {
  28.             throw new ZipFormatException("Invalid LOC header");
  29.          } else {
  30.             this.pos += (long)var4;
  31.             this.count -= (long)var4;
  32.             return var4;
  33.          }
  34.       }
  35.    }
  36.  
  37.    public synchronized int read() throws ZipFormatException, IOException {
  38.       if (this.count == 0L) {
  39.          return -1;
  40.       } else {
  41.          int var1 = this.zipFile.read();
  42.          if (var1 == -1) {
  43.             throw new ZipFormatException("Invalid LOC header");
  44.          } else {
  45.             ++this.pos;
  46.             --this.count;
  47.             return var1;
  48.          }
  49.       }
  50.    }
  51.  
  52.    public synchronized long skip(long var1) {
  53.       if (var1 > this.count) {
  54.          var1 = this.count;
  55.       }
  56.  
  57.       this.pos += var1;
  58.       this.count -= var1;
  59.       return var1;
  60.    }
  61.  
  62.    private void init() throws ZipFormatException, IOException {
  63.       byte[] var1 = new byte[30];
  64.       this.zipFile.read(this.zipEntry.locpos, var1, 0, 30);
  65.       byte[] var2 = ZipConstants.LOCSIG;
  66.       if (!ZipFile.checkSig(var1, 0, var2)) {
  67.          throw new ZipFormatException("Invalid LOC header signature");
  68.       } else if ((var1[8] & 255 | (var1[9] & 255) << 8) != 0) {
  69.          throw new ZipFormatException("Compressed entries not supported");
  70.       } else if (((var1[6] & 255 | (var1[7] & 255) << 8) & 1) == 1) {
  71.          throw new ZipFormatException("Encrypted entries not supported");
  72.       } else {
  73.          this.count = this.zipEntry.length;
  74.          this.pos = this.zipEntry.locpos + 30L + (long)(var1[26] & 255 | (var1[27] & 255) << 8) + (long)(var1[28] & 255 | (var1[29] & 255) << 8);
  75.          if (this.pos + this.count > this.zipFile.cenpos) {
  76.             throw new ZipFormatException("Invalid LOC header format");
  77.          }
  78.       }
  79.    }
  80. }
  81.